<?php 
    // 根据用户邮箱获取用户头像
    // email => image

    // 引入连接和关闭连接（数据）
    require_once '../../common/DBHelper.php';
    $res = ['code' => 0,'msg' =>'非法操作！'];
    // 1.接收传递过来的邮箱
    if(empty($_POST['email'])){
        $res['msg'] = '缺少必要参数';
    }
    $email = $_POST['email'];

    // 2.查询对应的头像地址
    $conn = conn();
    if(!$conn){
        $res['msg'] = '连接数据库失败';
    }
    $data = query($conn, "select avatar from users where email='{$email}';");
    if(!$data){
        $res['msg'] = '查询失败';
    }else{
        $res['code'] = 1;
        $res['msg'] = '查询成功';
        $res['data'] = $data[0];
    }
    
    // echo $data['avatar'];
    close($conn);
    echo json_encode($res, JSON_UNESCAPED_UNICODE);
?>